package com.piece.core.pay.client;

import com.piece.core.framework.exception.ErrorCode;
import lombok.extern.slf4j.Slf4j;

/**
 * 转换错误码
 */
@Slf4j
public abstract class AbstractPayResponseMapping {

    public final ErrorCode apply(String apiCode, String apiMsg) {
        if (null == apiCode) {
            log.error("[支付API错误码为空，请排查]");
            return ErrorCode.RUNTIME;
        }
        ErrorCode errorCode = this.convert(apiCode, apiMsg);
        if (null == errorCode) {
            log.error("[支付API错误码({}) 错误提示({}) 无法匹配]", apiCode, apiMsg);
            return ErrorCode.SERVER;
        }
        return errorCode;
    }

    protected abstract ErrorCode convert(String apiCode, String apiMsg);
}
